// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.core.skinnedmodel.model;

import java.io.File;
import java.io.IOException;
import java.util.Locale;
import zombie.core.skinnedmodel.model.jassimp.ProcessedAiScene;
import zombie.debug.DebugLog;
import zombie.debug.DebugOptions;
import zombie.fileSystem.FileSystem;
import zombie.fileSystem.FileTask;
import zombie.fileSystem.IFileTaskCallback;

public abstract class FileTask_AbstractLoadModel extends FileTask {
    protected String m_fileName;
    private final String m_mediaFilePath;
    private final String m_mediaFileXPath;

    protected FileTask_AbstractLoadModel(FileSystem fileSystem, IFileTaskCallback iFileTaskCallback, String string0, String string1) {
        super(fileSystem, iFileTaskCallback);
        this.m_mediaFilePath = string0;
        this.m_mediaFileXPath = string1;
    }

    public Object call() throws Exception {
        this.checkSlowLoad();
        ModelFileExtensionType modelFileExtensionType = this.checkExtensionType();
        switch (modelFileExtensionType) {
            case X:
                return this.loadX();
            case Fbx:
                return this.loadFBX();
            case Txt:
                return this.loadTxt();
            case None:
            default:
                return null;
        }
    }

    private void checkSlowLoad() {
        if (DebugOptions.instance.AssetSlowLoad.getValue()) {
            try {
                Thread.sleep(500L);
            } catch (InterruptedException interruptedException) {
            }
        }
    }

    private ModelFileExtensionType checkExtensionType() {
        String string0 = this.getRawFileName();
        String string1 = string0.toLowerCase(Locale.ENGLISH);
        if (string1.endsWith(".txt")) {
            return ModelFileExtensionType.Txt;
        } else {
            boolean _boolean = string0.startsWith("x:");
            if (_boolean) {
                DebugLog.Animation.warn("Note: The 'x:' prefix is not required. name=\"" + string0 + "\"");
                string1 = string0.substring(2);
            }

            if (string0.contains("media/") || string0.contains(".")) {
                this.m_fileName = string0;
                this.m_fileName = zombie.ZomboidFileSystem.instance.getString(this.m_fileName);
                if (new File(this.m_fileName).exists()) {
                    if (this.m_fileName.endsWith(".fbx")) {
                        return ModelFileExtensionType.Fbx;
                    }

                    if (this.m_fileName.endsWith(".x")) {
                        return ModelFileExtensionType.X;
                    }

                    return ModelFileExtensionType.X;
                }
            }

            this.m_fileName = this.m_mediaFileXPath + "/" + string1 + ".fbx";
            this.m_fileName = zombie.ZomboidFileSystem.instance.getString(this.m_fileName);
            if (new File(this.m_fileName).exists()) {
                return ModelFileExtensionType.Fbx;
            } else {
                this.m_fileName = this.m_mediaFileXPath + "/" + string1 + ".x";
                this.m_fileName = zombie.ZomboidFileSystem.instance.getString(this.m_fileName);
                if (new File(this.m_fileName).exists()) {
                    return ModelFileExtensionType.X;
                } else if (_boolean) {
                    return ModelFileExtensionType.None;
                } else {
                    if (!string1.endsWith(".x")) {
                        this.m_fileName = this.m_mediaFilePath + "/" + string1 + ".txt";
                        if (string0.contains("media/")) {
                            this.m_fileName = string0;
                        }

                        this.m_fileName = zombie.ZomboidFileSystem.instance.getString(this.m_fileName);
                        if (new File(this.m_fileName).exists()) {
                            return ModelFileExtensionType.Txt;
                        }
                    }

                    return ModelFileExtensionType.None;
                }
            }
        }
    }

    public abstract String getRawFileName();

    public abstract ProcessedAiScene loadX() throws IOException;

    public abstract ProcessedAiScene loadFBX() throws IOException;

    public abstract ModelTxt loadTxt() throws IOException;
}
